﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL.BusinessRules
{
    public class ValidateLength : BusinessRule
    {
        private int _max;
        private int _min;

        public ValidateLength(string propertyName, int min, int max)
            : base(propertyName)
        {
            _min = min;
            _max = max;
            ErrorMessage = string.Format("{0} must between {1} and {2} characters long.", propertyName, min, max);
        }

        public ValidateLength(string propertyName, string errorMessage, int min, int max)
            : this(propertyName, min, max)
        {
            ErrorMessage = errorMessage;
        }

        public override bool Validate(BusinessObject businessObject)
        {
            int length = GetPropertyValue(businessObject).ToString().Length;
            return (length >= _min && length <= _max);
        }
    }
}
